package com.yuedou.api.controller.product;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yuedou.api.constant.ResponseCode;
import com.yuedou.api.controller.platform.BaseController;
import com.yuedou.api.entity.dto.ProductCartDto;
import com.yuedou.api.entity.mer.Mer;
import com.yuedou.api.entity.mer.MerUser;
import com.yuedou.api.entity.platform.SearchData;
import com.yuedou.api.entity.product.*;
import com.yuedou.api.entity.wxuser.User;
import com.yuedou.api.entity.wxuser.UserAddress;
import com.yuedou.api.pay.nongshang.OrderUtil;
import com.yuedou.api.service.mer.MerService;
import com.yuedou.api.service.mer.MerUserService;
import com.yuedou.api.service.platfom.ParameterService;
import com.yuedou.api.service.platfom.SearchDataService;
import com.yuedou.api.service.platfom.WxTemplateService;
import com.yuedou.api.service.product.*;
import com.yuedou.api.service.wxuser.UserAddressService;
import com.yuedou.api.service.wxuser.UserCollectionService;
import com.yuedou.api.service.wxuser.UserService;

import com.yuedou.api.util.*;
import com.yuedou.api.websocket.WebSocketServer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;

/**
 *@Author: ZhouWei
 *@Description:  用户技能相关接口
 *@Date 2025-01-17
 */
@Component
@RestController
@RequestMapping("/product")//url:模块/资源/{}/细分
public class ProductController extends BaseController {
    @Resource
    private UserService userService;
    @Resource
    private UserAddressService userAddressService;
    @Resource
    private ProductService productService;
    @Resource
    private ProductImgService productImgService;
    @Resource
    private OrderAppraiseService orderAppraiseService;
    @Resource
    private ProductAttrValueService productAttrValueService;
    @Resource
    private ProductCartService productCartService;
    @Resource
    private UserCollectionService userCollectionService;
    @Resource
    private MerService merService;
    @Resource
    private MerUserService merUserService;
    @Resource
    private ProductRuleService ruleService;
    @Resource
    private ProductTypeService productTypeService;
    @Resource
    private SearchDataService searchDataService;
    @Resource
    private WxTemplateService templateService;


    @Value("${web.uploadPath}")
    private String uploadPath;//图片地址

    /**
     *  测试
     * @return
     */
    @PostMapping(value = "/test")
    public JSONObject test(@RequestBody String requestParam, HttpServletRequest request){
        JSONObject ret = null;
        try{
            if(StrUtil.isEmpty(requestParam)){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"参数异常"),true,true);
            }
            JSONObject jsonRequest = JSONUtil.parseObj(requestParam);
            int user_id = jsonRequest.containsKey("user_id") ? jsonRequest.getInt("user_id") : 0;
            long order_id = jsonRequest.containsKey("order_id") ? jsonRequest.getInt("order_id") : 0L;

            User user = userService.findById(user_id);

            String accessToken = templateService.getAccessToken(2);
            //String accessToken, String openid, String item_desc,String receiver_contact, String out_trade_no,String mchid
            String res = OrderUtil.uploadOrder(accessToken, user.getOpenId(), "测试", "测试", "202412180000001", "");
            System.out.println("res" + res);


        }catch (Exception e){
            e.printStackTrace();
        }
        return ret;
    }

    /**
     * 修改购物车商品的选中状态
     * @param
     * @throws Exception
     */
    @PostMapping(value="/add")
    public JSONObject addProduct(@RequestBody String requestParam) throws Exception{
        JSONObject result = null;
        try{
            if(StrUtil.isEmpty(requestParam)){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"参数异常"),true,true);
            }
            logBefore(logger, "product/add 接收的参数： "+requestParam);
            JSONObject jsonRequest = JSONUtil.parseObj(requestParam);
            int user_id = jsonRequest.containsKey("user_id") ? jsonRequest.getInt("user_id") : 0;
            long product_id = jsonRequest.containsKey("product_id") ? jsonRequest.getLong("product_id") : 0;
            int save_index = jsonRequest.containsKey("save_index") ? jsonRequest.getInt("save_index") : -1;
            int mer_id = jsonRequest.containsKey("mer_id") ? jsonRequest.getInt("mer_id") : 0;
            String deleteImgIds = jsonRequest.containsKey("deleteImgIds") ? jsonRequest.getStr("deleteImgIds") : null;
            JSONObject productJson = jsonRequest.containsKey("product") ? jsonRequest.getJSONObject("product") : null;

            User user = userService.findById(user_id);
            if(user == null){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"该用户不存在"),true,true);
            }

            MerUser merUser = merUserService.getMerByUser(user_id,mer_id);
            if(merUser == null){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"您无该商家权限"),true,true);
            }

            Product tempProduct = JSONUtil.toBean(productJson,Product.class);
            long productId = productService.addProduct(tempProduct,save_index, mer_id);
            if(productId > 0){
                if(StrUtil.isNotEmpty(deleteImgIds)){
                    String[] delImgs = deleteImgIds.split(",");
                    for (String id : delImgs){
                        productImgService.removeById(id);
                    }
                }
                result = Tools.getJson(new GsonResultBean<>(ResponseCode.OK,"保存成功",productId),true,false);
            }else{
                result = Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"保存失败"),true,true);
            }
        }catch (Exception e){
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.ERROR,"系统异常",e.getMessage()),true,true);
            System.out.println(e.getMessage());
            logger.error(e.getMessage(), e);
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 获取商品的详情  old
     * @param
     * @throws Exception
     */
    @PostMapping(value="/detail")
    public JSONObject getDetailInfo1(@RequestBody String requestParam) throws Exception{
        JSONObject result = null;
        Map<String,Object> map = new HashMap<>();
        try{
            if(StrUtil.isEmpty(requestParam)){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"参数异常"),true,true);
            }
            logBefore(logger, "product/detail 接收的参数： "+requestParam);
            JSONObject jsonRequest = JSONUtil.parseObj(requestParam);
            int product_id = jsonRequest.containsKey("product_id") ? jsonRequest.getInt("product_id") : 0;
            int user_id = jsonRequest.containsKey("user_id") ? jsonRequest.getInt("user_id") : 0;

            int is_mer_edit = jsonRequest.containsKey("is_mer_edit") ? jsonRequest.getInt("is_mer_edit") : 0;
            int mer_id = jsonRequest.containsKey("mer_id") ? jsonRequest.getInt("mer_id") : 0;

            //1. Product 商品属性
            Product product = productService.getProductInfoById(product_id, 0);
            if(is_mer_edit == 0){
                if(product == null){
                    return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"该商品不存在"),true,true);
                }

                if(product.getMerId()!=null){
                    Mer mer = merService.findById(product.getMerId());
                    if(mer!=null){
                        map.put("mer",mer);
                    }
                }
            }

            if(is_mer_edit == 0){
                QueryWrapper<ProductCart> qw = new QueryWrapper<>();
                qw.select("id");
                qw.eq("is_pay",0);
                qw.eq("is_del",0);
                long cartCount = productCartService.count(qw);
                map.put("cart_count",cartCount);

                //2. 轮播图  ProductImg
                //5. 评论列表 ProductOrderAppraise  product_order_appraise
                List<OrderAppraise> appraises = orderAppraiseService.selectByProductId(product_id,1,1);
                //6. 是否收藏的状态
                //8.评论数量
                QueryWrapper<OrderAppraise> qwAppraise = new QueryWrapper<>();
                qwAppraise.eq("product_id",product_id);
                long appraiseCount = orderAppraiseService.count(qwAppraise);
                map.put("appraiseCount",appraiseCount);
                map.put("appraises",appraises);
                map.put("isCollect",0);

                long isCollect = userCollectionService.getCollectionCount(user_id,product_id);
                if(isCollect > 0){
                    map.put("isCollect",1);
                }
            }
            map.put("product",product);
            map.put("user_id",user_id);


            List<String> names = new ArrayList<>();
            List<ProductType> types = productTypeService.selectListByColumn("parent_id",2);
            if(CollUtil.isNotEmpty(types)){
                for (ProductType type : types){
                    names.add(type.getTypeName());
                }
            }
            map.put("types",types);
            map.put("type_names",names);

            if(product_id > 0 && is_mer_edit == 1){
                Mer mer = merService.findById(mer_id);
                List<String> ruleNames = new ArrayList<>();
                if(mer!=null && mer.getCateChildId()!=null){
                    List<ProductRule> listRule = ruleService.getRulesByCateChildId(mer.getCateChildId());
                    if(CollUtil.isNotEmpty(listRule)){
                        for (ProductRule rule : listRule){
                            if(StrUtil.isNotEmpty(rule.getRuleValue())){
                                rule.setRuleValueArray(JSONUtil.parseArray(rule.getRuleValue()));
                            }
                            ruleNames.add(rule.getRuleName());
                        }
                    }
                    map.put("rules",listRule);
                }

                ProductRule rule = ruleService.findById(product.getRuleId());
                if(rule != null){
                    map.put("rule_name",rule.getRuleName());
                }
                map.put("rule_names",ruleNames);
            }

            result = Tools.getJson(new GsonResultBean<>(ResponseCode.OK,"成功", map),true,false);
        }catch (Exception e){
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.ERROR,"系统异常",e.getMessage()),true,true);
            logger.error(e.toString(), e);
            System.out.println("" + e.getMessage());
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 获取商品的详情  old
     * @param
     * @throws Exception
     */
    @PostMapping(value="/isFormatAttr")
    public JSONObject isFormatAttr(@RequestBody String requestParam) throws Exception{
        JSONObject result = null;
        Map<String,Object> map = new HashMap<>();
        try{
            if(StrUtil.isEmpty(requestParam)){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"参数异常"),true,true);
            }
            logBefore(logger, "product/detail 接收的参数： "+requestParam);
            JSONObject jsonRequest = JSONUtil.parseObj(requestParam);
            int user_id = jsonRequest.containsKey("user_id") ? jsonRequest.getInt("user_id") : 0;
            long product_id = jsonRequest.containsKey("product_id") ? jsonRequest.getLong("product_id") : 0;
            int is_reset = jsonRequest.containsKey("is_reset") ? jsonRequest.getInt("is_reset") : 0;
            String jsonStr = jsonRequest.containsKey("jsonStr") ? jsonRequest.getStr("jsonStr") : "";

            //1. Product 商品属性
            map = productService.getFormatAttr(product_id,jsonStr,false,is_reset);
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.OK,"成功", map),true,false);
        }catch (Exception e){
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.ERROR,"系统异常",e.getMessage()),true,true);
            logger.error(e.toString(), e);
            System.out.println("" + e.getMessage());
            e.printStackTrace();
        }
        return result;
    }

    /** 获取商品列表
     * @param
     * @throws Exception
     */
    @PostMapping(value="/list")
    public JSONObject list(@RequestBody String requestParam) throws Exception{
        JSONObject result = null;
        try{
            if(StrUtil.isEmpty(requestParam)){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"参数异常"),true,true);
            }
            logBefore(logger, "product/list 接收的参数： "+requestParam);
            JSONObject jsonRequest = JSONUtil.parseObj(requestParam);
            int user_id = jsonRequest.containsKey("user_id") ? jsonRequest.getInt("user_id") : 0;
            int type_id = jsonRequest.containsKey("type_id") ? jsonRequest.getInt("type_id") : 0;
            int pageIndex = jsonRequest.containsKey("pageIndex") ? jsonRequest.getInt("pageIndex") : 0;
            int pageSize = jsonRequest.containsKey("pageSize") ? jsonRequest.getInt("pageSize") : 0;
            String keyword =  jsonRequest.containsKey("keyword") ? jsonRequest.getStr("keyword") : null;
            int mer_id = jsonRequest.containsKey("mer_id") ? jsonRequest.getInt("mer_id") : 0;
            int is_mer = jsonRequest.containsKey("is_mer") ? jsonRequest.getInt("is_mer") : 0;
            int state = jsonRequest.containsKey("state") ? jsonRequest.getInt("state") : -1;
            String platform =  jsonRequest.containsKey("platform") ? jsonRequest.getStr("platform") : null;
            String mer_no =  jsonRequest.containsKey("mer_no") ? jsonRequest.getStr("mer_no") : null;


            if(StrUtil.isNotEmpty(keyword)){
                SearchData searchData = new SearchData();
                searchData.setCreateTime(new Date());
                searchData.setFromType("product");
                searchData.setUserId(user_id);
                searchData.setSearchWord(keyword);
                searchDataService.save(searchData);
            }

            if(StrUtil.isNotEmpty(mer_no)){
                QueryWrapper<Mer> qw = new QueryWrapper<>();
                qw.eq("shop_no", mer_no);
                qw.last("limit 1");
                Mer mer = merService.getOne(qw);
                if(mer != null){
                    mer_id = mer.getId();
                }
            }

            List<Product> list = productService.queryProductList(keyword,type_id,mer_id,state,is_mer,platform,pageIndex,pageSize);
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.OK,"成功", list.size(),list),false,false);
        }catch (Exception e){
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.ERROR,"系统异常",e.getMessage()),true,true);
            logger.error(e.toString(), e);
            System.out.println(""+e.getMessage());
            e.printStackTrace();
        }
        return result;
    }


    /** 获取商品列表
     * @param
     * @throws Exception
     */
    @PostMapping(value="/listBg")
    public JSONObject listBg(@RequestBody String requestParam) throws Exception{
        JSONObject result = null;
        Map<String, Object> map = new HashMap<>();
        try{
            if(StrUtil.isEmpty(requestParam)){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"参数异常"),true,true);
            }
            logBefore(logger, "product/list 接收的参数： "+requestParam);
            JSONObject jsonRequest = JSONUtil.parseObj(requestParam);
            int user_id = jsonRequest.containsKey("user_id") ? jsonRequest.getInt("user_id") : 0;
            int type_id = jsonRequest.containsKey("type_id") ? jsonRequest.getInt("type_id") : 0;
            int pageIndex = jsonRequest.containsKey("pageIndex") ? jsonRequest.getInt("pageIndex") : 0;
            int pageSize = jsonRequest.containsKey("pageSize") ? jsonRequest.getInt("pageSize") : 0;
            String keyword =  jsonRequest.containsKey("keyword") ? jsonRequest.getStr("keyword") : null;
            String platform =  jsonRequest.containsKey("platform") ? jsonRequest.getStr("platform") : null;

            if(StrUtil.isNotEmpty(keyword)){
                SearchData searchData = new SearchData();
                searchData.setCreateTime(new Date());
                searchData.setFromType("product");
                searchData.setUserId(user_id);
                searchData.setSearchWord(keyword);
                searchDataService.save(searchData);
            }

            QueryWrapper<ProductType> qwType = new QueryWrapper<>();
            qwType.eq("parent_id", 1);
            qwType.eq("state", 0);
            qwType.eq("is_show", 1);
            List<ProductType> typeList = productTypeService.list(qwType);
            map.put("typeList",typeList);
            if(type_id == 0){
                type_id = typeList.get(0).getId();
            }

            List<Product> products = productService.queryProductList(keyword,0,1,type_id, platform,pageIndex,pageSize);
            map.put("products",products);


            //String productName, Integer isHot, int cateId, int cateChildId, String platform,int pageIndex, int pageSize
//            List<Product> list = productService.queryProductList(keyword,0,1,type_id,platform,pageIndex,pageSize);
//            map.put("products", list);
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.OK,"成功", products.size(), map),false,false);
        }catch (Exception e){
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.ERROR,"系统异常",e.getMessage()),true,true);
            logger.error(e.toString(), e);
            System.out.println(""+e.getMessage());
            e.printStackTrace();
        }
        return result;
    }


    /** 获取商品列表
     * @param
     * @throws Exception
     */
    @PostMapping(value="/list/new")
    public JSONObject listNew(@RequestBody String requestParam) throws Exception{
        JSONObject result = null;
        Map<String,Object> map = new HashMap<>();
        try{
            if(StrUtil.isEmpty(requestParam)){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"参数异常"),true,true);
            }
            logBefore(logger, "product/list/new 接收的参数： "+requestParam);
            JSONObject jsonRequest = JSONUtil.parseObj(requestParam);
            int user_id = jsonRequest.containsKey("user_id") ? jsonRequest.getInt("user_id") : 0;
            int type_id = jsonRequest.containsKey("type_id") ? jsonRequest.getInt("type_id") : 0;
            int pageIndex = jsonRequest.containsKey("pageIndex") ? jsonRequest.getInt("pageIndex") : 0;
            int pageSize = jsonRequest.containsKey("pageSize") ? jsonRequest.getInt("pageSize") : 0;
            String keyword =  jsonRequest.containsKey("keyword") ? jsonRequest.getStr("keyword") : null;
            int mer_id = jsonRequest.containsKey("mer_id") ? jsonRequest.getInt("mer_id") : 0;
            int is_mer = jsonRequest.containsKey("is_mer") ? jsonRequest.getInt("is_mer") : 0;
            int state = jsonRequest.containsKey("state") ? jsonRequest.getInt("state") : -1;
            String platform =  jsonRequest.containsKey("platform") ? jsonRequest.getStr("platform") : "wxmini";
            String mer_no =  jsonRequest.containsKey("mer_no") ? jsonRequest.getStr("mer_no") : null;

            if(StrUtil.isNotEmpty(keyword)){
                SearchData searchData = new SearchData();
                searchData.setCreateTime(new Date());
                searchData.setFromType("product");
                searchData.setUserId(user_id);
                searchData.setSearchWord(keyword);
                searchDataService.save(searchData);
            }

            if(StrUtil.isNotEmpty(mer_no)){
                QueryWrapper<Mer> qw = new QueryWrapper<>();
                qw.eq("shop_no", mer_no);
                qw.last("limit 1");
                Mer mer = merService.getOne(qw);
                if(mer != null){
                    mer_id = mer.getId();
                }
                map.put("mapName", mer.getShopName());
            }

            List<Product> list = productService.queryProductList(keyword,type_id,mer_id,state,is_mer,platform,pageIndex,pageSize);

            map.put("productList", list);


            result = Tools.getJson(new GsonResultBean<>(ResponseCode.OK,"成功", list.size(), map),false,false);
        }catch (Exception e){
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.ERROR,"系统异常",e.getMessage()),true,true);
            logger.error(e.toString(), e);
            System.out.println(""+e.getMessage());
            e.printStackTrace();
        }
        return result;
    }

    /** 获取商品列表
     * @param
     * @throws Exception
     */
    @PostMapping(value="/restaurant/list")
    public JSONObject restaurantList(@RequestBody String requestParam) throws Exception{
        JSONObject result = null;
        try{
            if(StrUtil.isEmpty(requestParam)){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"参数异常"),true,true);
            }
            logBefore(logger, "product/restaurant/list 接收的参数： "+requestParam);
            JSONObject jsonRequest = JSONUtil.parseObj(requestParam);
            int user_id = jsonRequest.containsKey("user_id") ? jsonRequest.getInt("user_id") : 0;
            int type_id = jsonRequest.containsKey("type_id") ? jsonRequest.getInt("type_id") : 0;
            int pageIndex = jsonRequest.containsKey("pageIndex") ? jsonRequest.getInt("pageIndex") : 0;
            int pageSize = 100;// jsonRequest.containsKey("pageSize") ? jsonRequest.getInt("pageSize") : 10;
            String keyword =  jsonRequest.containsKey("keyword") ? jsonRequest.getStr("keyword") : null;
            int mer_id = jsonRequest.containsKey("mer_id") ? jsonRequest.getInt("mer_id") : 0;
            int table_id = jsonRequest.containsKey("table_id") ? jsonRequest.getInt("table_id") : 0;
            int order_id = jsonRequest.containsKey("order_id") ? jsonRequest.getInt("order_id") : 0;

//            if(StrUtil.isNotEmpty(keyword)){
//                SearchData searchData = new SearchData();
//                searchData.setCreateTime(new Date());
//                searchData.setFromType("product");
//                searchData.setUserId(user_id);
//                searchData.setSearchWord(keyword);
//                searchDataService.save(searchData);
//            }
//            String productName,int productTypeId,int mer_id, int pageIndex, int pageSize
            List<Product> list = productService.queryMerProductList(keyword,type_id,mer_id,table_id,order_id,pageIndex,pageSize,1);
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.OK,"成功", list.size(),list),false,false);
        }catch (Exception e){
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.ERROR,"系统异常",e.getMessage()),true,true);
            logger.error(e.toString(), e);
            System.out.println(""+e.getMessage());
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 获取购物车列表
     * @param
     * @throws Exception
     */
    @PostMapping(value="/cart/list")
    public JSONObject cartList(@RequestBody String requestParam) throws Exception{
        JSONObject result = null;
        try{
            if(StrUtil.isEmpty(requestParam)){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"参数异常"),true,true);
            }
            logBefore(logger, "product/cart/list 接收的参数： "+requestParam);
            JSONObject jsonRequest = JSONUtil.parseObj(requestParam);
            int user_id = jsonRequest.containsKey("user_id") ? jsonRequest.getInt("user_id") : 0;
            Integer checkState = jsonRequest.containsKey("check_state") ? jsonRequest.getInt("check_state") : null;

            List<ProductCartDto> list = productCartService.selectAllMerByUserId(user_id,checkState);

            result = Tools.getJson(new GsonResultBean<>(ResponseCode.OK,"成功", list.size(),list),false,false);
        }catch (Exception e){
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.ERROR,"系统异常",e.getMessage()),true,true);
            logger.error(e.toString(), e);
            System.out.println(""+e.getMessage());
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 购物车跳转到  订单结算 界面数据
     * @param
     * @throws Exception
     */
    @PostMapping(value="/cart/previewList")
    public JSONObject PreviewOrdepreviewListrList(@RequestBody String requestParam) throws Exception{
        JSONObject result = null;
        Map<String,Object> map = new HashMap<>();
        try{
            if(StrUtil.isEmpty(requestParam)){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"参数异常"),true,true);
            }
            JSONObject jsonRequest = JSONUtil.parseObj(requestParam);
            int user_id = jsonRequest.containsKey("user_id") ? jsonRequest.getInt("user_id") : 0;
            int mer_id = jsonRequest.containsKey("mer_id") ? jsonRequest.getInt("mer_id") : 0;
            int table_id = jsonRequest.containsKey("table_id") ? jsonRequest.getInt("table_id") : 0;

            User user = userService.findById(user_id);
            if(user == null){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"该用户不存在"),true,true);
            }

            //1.先获取父节点
            List<ProductCart> list = productCartService.selectByTableId(mer_id,table_id,1);
            double allPrice = 0, payPrice = 0;
            for (ProductCart cart : list){
                ProductAttrValue attrValue = productAttrValueService.findById(cart.getProductAttValueId());
                if(attrValue!=null){
                    double currentPrice = cart.getCartNum() * attrValue.getPrice().doubleValue();
                    allPrice += currentPrice;
                }
                payPrice = allPrice;
            }
            map.put("allPrice",MathUtil.getDoubleUp(allPrice));
            map.put("cars",list);
            map.put("car_count",list.size());
            map.put("is_has_address",0);
            QueryWrapper<UserAddress> qw = new QueryWrapper<>();
            qw.eq("user_id",user_id);
            qw.eq("is_default",1);
            qw.last("limit 1");
            UserAddress userAddress = userAddressService.getOne(qw);
            if(userAddress != null){
                map.put("is_has_address", 1);
                map.put("address",userAddress);
            }
            map.put("payPrice", MathUtil.getDoubleUp(payPrice));
            map.put("payPriceFen", MathUtil.getDoubleUp(payPrice * 100) );


            map.put("mer_name", "");
            Mer mer = merService.findById(mer_id);
            if(mer!= null){
                map.put("mer_name", mer.getShopName());
            }

            result = Tools.getJson(new GsonResultBean<>(ResponseCode.OK,"成功", map),true,false);
        }catch (Exception e){
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"系统异常",e.getMessage()),true,true);
            logger.error(e.toString(), e);
            System.out.println(""+e.getMessage());
        }
        return result;
    }

    /**
     * 获取当前商家的所有分类
     * @param
     * @throws Exception
     */
    @PostMapping(value="/addCartRefresh")
    public JSONObject addCartRefresh(@RequestBody String requestParam) throws Exception{
        JSONObject result = null;
        try{
            if(StrUtil.isEmpty(requestParam)){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"参数异常"),true,true);
            }
            JSONObject jsonRequest = JSONUtil.parseObj(requestParam);
            int user_id = jsonRequest.containsKey("user_id") ? jsonRequest.getInt("user_id") : 0;
            int mer_id = jsonRequest.containsKey("mer_id") ? jsonRequest.getInt("mer_id") : 0;
            int table_id = jsonRequest.containsKey("table_id") ? jsonRequest.getInt("table_id") : 0;
            int cateId = jsonRequest.containsKey("cateId") ? jsonRequest.getInt("cateId") : 0;
            int pageIndex = jsonRequest.containsKey("pageIndex") ? jsonRequest.getInt("pageIndex") : 1;
            int pageSize = 200;// jsonRequest.containsKey("pageSize") ? jsonRequest.getInt("pageSize") : 100;
            String keyword = jsonRequest.containsKey("keyword") ? jsonRequest.getStr("keyword") : null;

            Map<String,Object> map = new HashMap<>();

            //1.先获取父节点
            List<ProductCart> cartList = productCartService.selectByTableId(mer_id,table_id,1);
            double allPrice = 0, payPrice = 0;
            for (ProductCart cart : cartList){
                ProductAttrValue attrValue = productAttrValueService.findById(cart.getProductAttValueId());
                if(attrValue!=null){
                    double currentPrice = cart.getCartNum() * attrValue.getPrice().doubleValue();
                    allPrice += currentPrice;
                }
                payPrice = allPrice;
            }
            map.put("allPrice", MathUtil.getDoubleUp(allPrice));
            map.put("cars",cartList);
            map.put("car_count",cartList.size());
            map.put("is_has_address",0);
            map.put("payPrice", MathUtil.getDoubleUp(payPrice));
            map.put("payPriceFen", MathUtil.getDoubleUp(payPrice * 100));

            //只搜索 商品
            List<Product> products = productService.queryMerProductList(keyword,cateId,mer_id,table_id,0,pageIndex,pageSize,1);
            map.put("products",products);
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.OK,"成功",products.size(), map),false,false);

        }catch (Exception e){
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"系统异常",e.getMessage()),true,true);
            logger.error(e.toString(), e);
        }
        return result;
    }

    /**  添加购物车
     * @param
     * @throws Exception
     */
    @PostMapping(value="/addCart")
    public JSONObject addCart(@RequestBody String requestParam) throws Exception{
        JSONObject result = null;
        Map<String,Object> map = new HashMap<>();
        try{
            if(StrUtil.isEmpty(requestParam)){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"参数异常"),true,true);
            }
            logBefore(logger, "product/addCart 接收的参数： "+requestParam);
            JSONObject jsonRequest = JSONUtil.parseObj(requestParam);
            int user_id = jsonRequest.containsKey("user_id") ? jsonRequest.getInt("user_id") : 0;
            int product_id = jsonRequest.containsKey("product_id") ? jsonRequest.getInt("product_id") : 0;
            int table_id = jsonRequest.containsKey("table_id") ? jsonRequest.getInt("table_id") : 0;
            int attr_value_id = jsonRequest.containsKey("attr_value_id") ? jsonRequest.getInt("attr_value_id") : 0;
            int count = jsonRequest.containsKey("count") ? jsonRequest.getInt("count") : 0;
            int cateId = jsonRequest.containsKey("cateId") ? jsonRequest.getInt("cateId") : 0;
            int order_id = jsonRequest.containsKey("order_id") ? jsonRequest.getInt("order_id") : 0;
            String keyword = jsonRequest.containsKey("keyword") ? jsonRequest.getStr("keyword") : null;

            User user = userService.findById(user_id);
            if(user == null){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"该用户不存在"),true,true);
            }

            Product product = productService.findById(product_id);
            if(product == null){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"该商品不存在"),true,true);
            }

            ProductAttrValue attrValue = productAttrValueService.findById(attr_value_id);
            if(attrValue == null){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"该商品规格不存在"),true,true);
            }

            boolean ret = false;
            QueryWrapper<ProductCart> qw = new QueryWrapper<>();
            qw.eq("is_del",0);
            qw.eq("is_pay",0);
            qw.eq("mer_id", product.getMerId());
            qw.eq("table_id",table_id);
            qw.eq("product_id",product_id);
            qw.eq("product_att_value_id",attr_value_id);
            qw.last("limit  1");
            ProductCart productCart = productCartService.getOne(qw);
            if(productCart == null){
                productCart = new ProductCart();
                productCart.setProductId(product_id);
                productCart.setMerId(product.getMerId());
                productCart.setTableId(table_id);
                productCart.setProductAttValueId(attr_value_id);
                productCart.setProductAttrUnique(attrValue.getUniqueValue());
                productCart.setIsPay(0);
                productCart.setSinglePrice(attrValue.getPrice());
                productCart.setProductName(product.getStoreName());
                productCart.setUserId(user_id);
                productCart.setIsDel(0);
                productCart.setCreateTime(new Date());
                productCart.setCheckState(1);
                productCart.setCartNum(count);

//                if(product.getDishType()!= null){
//                    productCart.setDishType(product.getDishType());
//                }else{
                    ProductType productType = productTypeService.findById(product.getCateId());
                    if(productType!= null){
                        productCart.setDishType(productType.getDishType());
                    }
//                }
                ret = productCartService.save(productCart);
            }else{
                productCart.setSinglePrice(attrValue.getPrice());
                productCart.setCheckState(1);
                productCart.setCartNum(productCart.getCartNum() + count);
                ret = productCartService.updateById(productCart);
            }

            map.put("cart", productCart);

            //1.先获取父节点
            List<ProductCart> list = productCartService.selectByTableId(product.getMerId(),table_id,1);
            double allPrice = 0, payPrice = 0;
            for (ProductCart cart : list){
                attrValue = productAttrValueService.findById(cart.getProductAttValueId());
                if(attrValue!=null){
                    double currentPrice = cart.getCartNum() * attrValue.getPrice().doubleValue();
                    allPrice += currentPrice;
                }
                payPrice = allPrice;
            }
            map.put("allPrice", MathUtil.getDoubleUp(allPrice));
            map.put("cars",list);
            map.put("car_count",list.size());
            map.put("payPrice", MathUtil.getDoubleUp(payPrice));
            map.put("payPriceFen", MathUtil.getDoubleUp(payPrice * 100));

//            if(cateId > 0) {
//                List<Product> products = productService.queryMerProductList(keyword, cateId, product.getMerId(),table_id,order_id, 1, 1000, 1);
//                map.put("products", products);
//            }

            if(ret){
                Map<String, Object> mapRet = new HashMap<>();
                mapRet.put("table_id", table_id);
                mapRet.put("user_id", user_id);
                String retData = JSONUtil.toJsonStr(Tools.getJson(new GsonResultBean<>(ResponseCode.OK, "同步成功", mapRet), true, false)) ;
                WebSocketServer webSocketServer = new WebSocketServer();
                webSocketServer.sendInfo(retData,null);
                result = Tools.getJson(new GsonResultBean<>(ResponseCode.OK,"添加成功",map),true,false);
            }else{
                result = Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"添加失败"),true,true);
            }
        }catch (Exception e){
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.ERROR,"系统异常",e.getMessage()),true,true);
            System.out.println(e.getMessage());
            logger.error(e.getMessage(), e);
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 删除购物车
     * @param
     * @throws Exception
     */
    @PostMapping(value="/delCart")
    public JSONObject delCart(@RequestBody String requestParam) throws Exception{
        JSONObject result = null;
        Map<String,Object> map = new HashMap<>();
        try{
            if(StrUtil.isEmpty(requestParam)){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"参数异常"),true,true);
            }
            logBefore(logger, "product/delCart 接收的参数： "+requestParam);
            JSONObject jsonRequest = JSONUtil.parseObj(requestParam);
            long user_id = jsonRequest.containsKey("user_id") ? jsonRequest.getInt("user_id") : 0;
            int cart_id = jsonRequest.containsKey("cart_id") ? jsonRequest.getInt("cart_id") : 0;
            //是否删除全部  0 - 删除单个  1 - 删除全部
            int is_all = jsonRequest.containsKey("is_all") ? jsonRequest.getInt("is_all") : 0;
            int mer_id = jsonRequest.containsKey("mer_id") ? jsonRequest.getInt("mer_id") : 0;
            int table_id = jsonRequest.containsKey("table_id") ? jsonRequest.getInt("table_id") : 0;
            int cateId = jsonRequest.containsKey("cateId") ? jsonRequest.getInt("cateId") : 0;
            int order_id = jsonRequest.containsKey("order_id") ? jsonRequest.getInt("order_id") : 0;
            String keyword = jsonRequest.containsKey("keyword") ? jsonRequest.getStr("keyword") : null;

            User user = userService.findById(user_id);
            if(user == null){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"该用户不存在"),true,true);
            }

            if(is_all == 0){
                ProductCart productCart = productCartService.findById(cart_id);
                if(productCart == null){
                    return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"该购物车商品不存在"),true,true);
                }
                boolean ret = productCartService.removeById(productCart.getId());
                if(ret){

                    if(cateId > 0) {
                        List<Product> products = productService.queryMerProductList(keyword, cateId, mer_id,table_id,order_id, 1, 1000,1);
                        map.put("products", products);
                    }

                    Map<String, Object> mapRet = new HashMap<>();
                    mapRet.put("table_id", table_id);
                    mapRet.put("user_id", user_id);
                    String retData = JSONUtil.toJsonStr(Tools.getJson(new GsonResultBean<>(ResponseCode.OK, "同步成功", mapRet), true, false)) ;
                    WebSocketServer webSocketServer = new WebSocketServer();
                    webSocketServer.sendInfo(retData,null);
                    result = Tools.getJson(new GsonResultBean<>(ResponseCode.OK,"删除成功",map),true,false);
                }else{
                    result = Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"删除失败"),true,true);
                }
            }else{
                boolean ret = productCartService.update(Wrappers.<ProductCart>lambdaUpdate()
                        .set(ProductCart::getIsDel,1)
                        .eq(ProductCart::getTableId,table_id)
                        .eq(ProductCart::getMerId,mer_id));
                if(ret){

                    if(cateId > 0) {
                        List<Product> products = productService.queryMerProductList(keyword, cateId, mer_id,table_id,order_id, 1, 1000,1);
                        map.put("products", products);
                    }

                    Map<String, Object> mapRet = new HashMap<>();
                    mapRet.put("table_id", table_id);
                    mapRet.put("user_id", user_id);
                    String retData = JSONUtil.toJsonStr(Tools.getJson(new GsonResultBean<>(ResponseCode.OK, "同步成功", mapRet), true, false)) ;
                    WebSocketServer webSocketServer = new WebSocketServer();
                    webSocketServer.sendInfo(retData,null);
                    result = Tools.getJson(new GsonResultBean<>(ResponseCode.OK,"清空成功",map),true,false);
                }else{
                    result = Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"清空失败"),true,true);
                }

            }

        }catch (Exception e){
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.ERROR,"系统异常",e.getMessage()),true,true);
            System.out.println(e.getMessage());
            logger.error(e.getMessage(), e);
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 修改购物车商品的选中状态
     * @param
     * @throws Exception
     */
    @PostMapping(value="/changeCartState")
    public JSONObject changeCartState(@RequestBody String requestParam) throws Exception{
        JSONObject result = null;
        try{
            if(StrUtil.isEmpty(requestParam)){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"参数异常"),true,true);
            }
            logBefore(logger, "product/changeCartState 接收的参数： "+requestParam);
            JSONObject jsonRequest = JSONUtil.parseObj(requestParam);
            long user_id = jsonRequest.containsKey("user_id") ? jsonRequest.getInt("user_id") : 0;
            long cart_id = jsonRequest.containsKey("cart_id") ? jsonRequest.getLong("cart_id") : 0;
            int check_state = jsonRequest.containsKey("check_state") ? jsonRequest.getInt("check_state") : 0;
            int is_all = jsonRequest.containsKey("is_all") ? jsonRequest.getInt("is_all") : 0;

            User user = userService.findById(user_id);
            if(user == null){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"该用户不存在"),true,true);
            }
            ProductCart cart = null;
            if(is_all == 0){
                cart = productCartService.findById(cart_id);
                if(cart == null){
                    return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"购物车没有此商品"),true,true);
                }
                cart.setCheckState(check_state);
            }

            int ret = productCartService.changeState(user_id,cart,check_state,is_all);
            if(ret > 0){
                result = Tools.getJson(new GsonResultBean<>(ResponseCode.OK,"修改成功"),true,true);
            }else{
                result = Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"修改失败"),true,true);
            }
        }catch (Exception e){
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.ERROR,"系统异常",e.getMessage()),true,true);
            System.out.println(e.getMessage());
            logger.error(e.getMessage(), e);
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 修改购物车商品的数量
     * @param
     * @throws Exception
     */
    @PostMapping(value="/changeCartNum")
    public JSONObject changeCartNum(@RequestBody String requestParam) throws Exception{
        JSONObject result = null;
        Map<String,Object> map = new HashMap<>();
        try{
            if(StrUtil.isEmpty(requestParam)){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"参数异常"),true,true);
            }
            logBefore(logger, "product/changeCartNum 接收的参数： "+requestParam);
            System.out.println("product/changeCartNum 接收的参数： "+requestParam);
            JSONObject jsonRequest = JSONUtil.parseObj(requestParam);
            int user_id = jsonRequest.containsKey("user_id") ? jsonRequest.getInt("user_id") : 0;
            long cart_id = jsonRequest.containsKey("cart_id") ? jsonRequest.getLong("cart_id") : 0;
            int count = jsonRequest.containsKey("count") ? jsonRequest.getInt("count") : 0;
            int cateId = jsonRequest.containsKey("cateId") ? jsonRequest.getInt("cateId") : 0;
            int mer_id = jsonRequest.containsKey("mer_id") ? jsonRequest.getInt("mer_id") : 0;
            int order_id = jsonRequest.containsKey("order_id") ? jsonRequest.getInt("order_id") : 0;
            String keyword = jsonRequest.containsKey("keyword") ? jsonRequest.getStr("keyword") : null;

            User user = userService.findById(user_id);
            if(user == null){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"该用户不存在"),true,true);
            }

            ProductCart cart = productCartService.findById(cart_id);
            if(cart == null){
                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"购物车没有此商品"),true,true);
            }
            cart.setCartNum(count);
            int table_id = cart.getTableId();

            boolean ret = false;
            if(count == 0){
                cart.setIsDel(1);
            }
            ret = productCartService.updateById(cart);
            if(ret){
                //1.先获取父节点
                List<ProductCart> cartList = productCartService.selectByTableId(cart.getMerId(),table_id,1);
                double allPrice = 0, payPrice = 0;
                for (ProductCart cart1 : cartList){
//                    ProductAttrValue attrValue = productAttrValueService.findById(cart1.getProductAttValueId());
//                    if(attrValue!=null){
                        double currentPrice = cart1.getCartNum() * cart1.getSinglePrice().doubleValue();
                        allPrice += currentPrice;
//                    }
                    payPrice = allPrice;
                }
                map.put("allPrice",MathUtil.getDoubleUp(allPrice));
                map.put("cars",cartList);
                map.put("car_count",cartList.size());
                map.put("is_has_address",0);
                map.put("payPrice",MathUtil.getDoubleUp(payPrice));
                map.put("payPriceFen", MathUtil.getDoubleUp(payPrice * 100));


//                if(cateId > 0){
//                    List<Product> products = productService.queryMerProductList(keyword,cateId, mer_id,table_id,order_id,1,1000,1);
//                    map.put("products",products);
//                }


                map.put("cart", cart);

                Map<String, Object> mapRet = new HashMap<>();
                mapRet.put("table_id", table_id);
                mapRet.put("user_id", user_id);
                String retData = JSONUtil.toJsonStr(Tools.getJson(new GsonResultBean<>(ResponseCode.OK, "同步成功", mapRet), true, false)) ;
                WebSocketServer webSocketServer = new WebSocketServer();
                webSocketServer.sendInfo(retData,null);

                result = Tools.getJson(new GsonResultBean<>(ResponseCode.OK,"修改成功",map),true,false);
            }else{
                result = Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"修改失败"),true,true);
            }
        }catch (Exception e){
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.ERROR,"系统异常",e.getMessage()),true,true);
            System.out.println(e.getMessage());
            logger.error(e.getMessage(), e);
            e.printStackTrace();
        }
        return result;
    }

    /**
     *  商品 上传图片
     * @param
     * @throws Exception
     */
    @PostMapping(value="/uploadImg")
    public JSONObject uploadImg(@RequestParam("product_id") int product_id, @RequestParam("img_type") int img_type, HttpServletRequest request) throws Exception{
        JSONObject result = null;
        Map<String,Object> map = new HashMap<>();
        try{
            System.out.println("product_id==" + product_id);

            // 创建一个通用的多部分解析器.
            CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver(request.getSession().getServletContext());
            // 设置编码
            commonsMultipartResolver.setDefaultEncoding("utf-8");
            // 判断是否有文件上传
            if (commonsMultipartResolver.isMultipart(request)) {//有文件上传
                //将request变成多部分request
                MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest)request;
                //获取multiRequest 中所有的文件名
                Iterator<String> iter = multiRequest.getFileNames();
                if (iter.hasNext()) {
                    Map<String, MultipartFile> maps = multiRequest.getFileMap();

                    for(String key : maps.keySet()) {
                        MultipartFile certurl = maps.get(key);
                        if (!certurl.isEmpty()) {
                            String prefix = certurl.getOriginalFilename().substring(certurl.getOriginalFilename().lastIndexOf(".") + 1);
                            if ("jpeg".equals(prefix) || "jpg".equals(prefix) || "png".equals(prefix)) {
                                String fileName = "common_info_img_" + new Date().getTime() + "." + prefix;// user_photo.getOriginalFilename();
                                try {
                                    byte[] byteImg = certurl.getBytes();
                                    if (byteImg != null) {
                                        //上传头像到OSS
                                        int upload_type = OssUtil.TYPE_PRODUCT_PHOTOS;
                                        String img_key = OssUtil.getUploadPrefix(upload_type) + DateUtil.getSdfYearDay() + "/" + fileName;

                                        String path = uploadPath + OssUtil.getUploadPrefix(upload_type) + DateUtil.getSdfYearDay() ;
                                        System.out.println("path: " + path);
                                        File file = new File(path);
                                        if (!file.exists() && !file.isDirectory()) {
                                            file.mkdirs();
                                        }

                                        String filePath =  path +"/" + fileName;
                                        FileOutputStream out = new FileOutputStream(filePath);
                                        out.write(certurl.getBytes());
                                        out.flush();
                                        out.close();

                                        ImagesFiler.imageResize(filePath,filePath);

//                                        OssUtil.upload(certurl.getInputStream(),fileName,upload_type);

                                        if(img_type == 0){
                                            Product product = productService.findById(product_id);
                                            if(product != null){
                                                product.setImage(img_key);
                                                productService.updateById(product);
                                            }

                                            QueryWrapper<ProductImg> qwImg = new QueryWrapper<>();
                                            qwImg.eq("product_id", product_id);
                                            qwImg.eq("img_type", 0);
                                            qwImg.last("limit 1");
                                            qwImg.orderByDesc("id");
                                            ProductImg proImg = productImgService.getOne(qwImg);
                                            if(proImg!=null){
                                                if(CollUtil.isNotEmpty(product.getProductImgs())){
                                                    if(product.getProductImgs().size() > 0) {
                                                        proImg.setImgUrl(img_key);
                                                        productImgService.updateById(proImg);
                                                    }
                                                }
                                            }else{
                                                if(CollUtil.isNotEmpty(product.getProductImgs())){
                                                    if(product.getProductImgs().size() > 0){
                                                        proImg = new ProductImg();
                                                        proImg.setProductId(product.getId());
                                                        proImg.setImgUrl(img_key);
                                                        proImg.setSort(0);
                                                        proImg.setImgType(0);
                                                        productImgService.save(proImg);
                                                    }
                                                }
                                            }
                                        }else{
                                            ProductImg infoImg = new ProductImg();
                                            infoImg.setProductId(product_id);
                                            infoImg.setImgType(img_type);
                                            infoImg.setSort(1);
                                            infoImg.setImgUrl(img_key);
                                            productImgService.save(infoImg);
                                        }
                                    }
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }
                }
            }
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.OK, "图片上传成功"), true, true);
        }catch (Exception e){
            e.printStackTrace();
            result = Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"系统异常",e.getMessage()),true,true);
            logger.error(e.toString(), e);
            System.out.println(""+e.getMessage());
        }
        return result;
    }
}
